package com.ruoyi.web.controller.tool;


import org.joda.time.Instant;

import java.util.Random;

public class ImgFileRename {

	private static Random random = new Random();

	/**
	 * 自动生成百万微秒文件名称
	 *
	 * @param fileName
	 * @return
	 */
	public static String imgFileRename(String fileName) {
		String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
		Instant instant = Instant.now();
		long ticketOrder = instant.getMillis();
		return ticketOrder + "." + suffix;
	}

	/**
	 * @param fileName
	 * @return String
	 * @description 自动生成百万微秒文件名称+四位随机数
	 * @author 柚子茶
	 * @date 2021/1/22 16:27
	 **/
	public static String imgRandomFileRename(String fileName) {
		String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
		Instant instant = Instant.now();
		long ticketOrder = instant.getMillis();
		int num = random.nextInt(9000)+1000;
		return ticketOrder + num + "." + suffix;
	}

	public static void main(String[] args) {
		String str = "abulasf.jpg";
		String aString = imgFileRename(str);
		System.out.println(aString);
	}
}

